// @ts-nocheck


const setUserInfo=(data:object)=>{
    window.localStorage.setItem('user-info',JSON.stringify(data))
}

const getUserInfo=()=>{
    const userInfo = window.localStorage.getItem('user-info')
    if(userInfo){
        return JSON.parse(userInfo)
    }else{
        return null
    }
}

const removeUserInfo=()=>{
    const userInfo = window.localStorage.getItem('user-info')
    if (userInfo) {
        window.localStorage.removeItem('user-info')
        return true
    } else {
        return null
    }
}

const setToken=(data:String)=>{
    window.localStorage.setItem('user-token',JSON.stringify(data))
}

const getToken=()=>{
    const token = window.localStorage.getItem('user-token')
    if (token){
        return JSON.parse(token)
    }else{
        return null
    }    
}

const removeToken=()=>{
    const token = window.localStorage.getItem('user-token')
    if (token) {
        window.localStorage.removeItem('user-token')
        return true
    } else {
        return null
    }
    
}


const replaceAll=(str:string, find:string, replace:string)=> {
    return str.replace(new RegExp(find, 'g'), replace);
}

const downloadBlob=(file:any, name:any, suffix = 'xls')=> {
    let a = document.createElement('a')
    let blob = new Blob([file], {
        type: 'application/vnd.ms-excel'
    })
    a.href = URL.createObjectURL(blob)
    let nowDate = new Date()
    a.download = name + nowDate.getFullYear() + '-' + (nowDate.getMonth() + 1) + '-' + nowDate.getDate() + '-' + Date.parse(new Date()) / 1000 + '.' + suffix
    a.click()
    document.body.appendChild(a)
}

export { setToken, getToken, removeToken, replaceAll, downloadBlob, setUserInfo, getUserInfo, removeUserInfo }